<template>
  <div>
<van-nav-bar
  title="账号登录"

/>
<van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label=""
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label=""
    placeholder="请输入密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button color='#1cb676' block type="info" native-type="submit">登录</van-button>
  </div>
</van-form>
<div class="zhuce">&nbsp;&nbsp;&nbsp;还没有账号，去注册~</div>
  </div>
</template>

<script>
import { setToken } from '@/utils/storage'
import { login } from '@/api/user'
import request from '@/utils/request'
// import router from '@/router'
export default {
  async created () {
    const res = await request.post('/user/login', {
      username: '',
      password: ''
    })
    console.log(res)
    setToken()
  },
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      console.log(values)
      const { body } = await login(values)
      console.log(body)
      // console.log(body.token)
      setToken(body.token)
      this.$toast.success('登录成功')
      this.$router.push('/')
    }

  }
}
</script>

<style scoped lang='less'>
.zhuce {
  color: gray;
  font-size: 12px;
}
</style>
